#ifndef IMAGELABELMODEL_H
#define IMAGELABELMODEL_H
#include <QString>
#include <QAbstractListModel>
#include <QJsonObject>
#include "BaseResult.h"
#include "LabelModel.h"

class ImageLabelModelData {

public :
    ImageLabelModelData(const int &seq, const QString &name, const QString &color,
                        const int &x1, const int &y1, const int &x2, const int &y2);

    ~ImageLabelModelData();
    QString getName() const;
    QString getColor() const;
    int getX1() const;
    int getX2() const;
    int getY1() const;
    int getY2() const;
    int getSeq() const;

    QJsonObject toJsonObject();

private :
    int seq;
    QString name;
    QString color;
    int x1;
    int y1;
    int x2;
    int y2;
};

class ImageLabelModel : public QAbstractListModel {
    Q_OBJECT
public:
    enum DataRoles{
        ROLE_NAME = 1, ROLE_COLOR, ROLE_X1, ROLE_X2, ROLE_Y1, ROLE_Y2
    };
public:
    static const bool PIEXL_MODE = true;
    ImageLabelModel(QString imageName);
    ImageLabelModel(QObject *parent = nullptr);

    ~ImageLabelModel();
    QString imageName() const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    Q_INVOKABLE QVariant data(const QModelIndex &index, int role = 1) const override;

    Q_INVOKABLE BaseResult::JsonResult append(const int &seq, const QString &name, const QString &color,
                                              const int &x1, const int &y1, const int &x2, const int &y2);
    Q_INVOKABLE BaseResult::JsonResult get(const int &index);

    Q_INVOKABLE BaseResult::JsonResult save();
    Q_INVOKABLE BaseResult::JsonResult resetModel(const int &index);

    static void setImageLabelSaveFilePath(const QString &savePath);
    static void setImageName(const QString &imageName);
    Q_INVOKABLE void loadImage(const int &index);
    Q_INVOKABLE void clearAll();

    Q_INVOKABLE BaseResult::JsonResult removeLast();

protected:
    virtual QHash<int, QByteArray> roleNames() const;
private:
    static QString _imageName_;
    static QString _imageLabelSaveFilePath_;
    QList<ImageLabelModelData> _dataList_;
};

#endif // IMAGELABELMODEL_H
